<?php

namespace Drupal\shushengyuan\Schemas;

use Drupal\shusy_service\Entity\ShusyService;

/**
 * @OA\Schema(
 *   schema="MyServiceItem",
 *   type="object",
 *   description="MyServiceItem"
 * )
 */
class MyServiceItem extends AbstractBaseModel {

  protected function getEntityType() {
    return 'shusy_service';
  }

  protected function setValue() {
    if ($this->entity instanceof ShusyService) {
      $value = [
        /**
         * @OA\Property(
         *   property="id",
         *   type="integer",
         *   description="ID",
         * ),
         */
        'id' => (int) $this->entity->id,
        /**
         * @OA\Property(
         *   property="service",
         *   ref="#/components/schemas/ServiceItem",
         *   description="服务",
         * ),
         */
        'service' => ServiceItem::get($this->entity->service_id),
        /**
         * @OA\Property(
         *   property="validity",
         *   type="string",
         *   description="有效期至",
         * ),
         */
        'validity' => $this->formatDate($this->entity->validity, 'Y-m-d H:i:s'),
        /**
         * @OA\Property(
         *   property="user",
         *   description="购买人",
         *   ref="#/components/schemas/User",
         * ),
         */
        'user' => User::get($this->entity->uid),
        /**
         * @OA\Property(
         *   property="store",
         *   description="所属店铺",
         *   ref="#/components/schemas/StoreItem",
         * ),
         */
        'store' => StoreItem::get($this->entity->store_id),
        /**
         * @OA\Property(
         *   property="order",
         *   description="所属订单信息",
         *   ref="#/components/schemas/OrderInfo",
         * ),
         */
        'order' => OrderInfo::get($this->entity->store_order_id),
      ];
      $this->merge($value);
    }
  }
}
